<template>
  <InlineLayout title-name="退费列表">
    <template #header>
      <my-form ref="queryFormRef" v-model:modelValue="queryParams" :model="queryParams" :items-datas="itemsDatas">
        <my-button type="reset" title="重置" @click="reset" />
        <my-button type="search" title="查询" :loading="loading" @click="handleQuery" />
      </my-form>
    </template>
    <my-table :columns="columns" :table-data="tableData" @selection-change="handleSelectionChange">
      <template #refStatus="scope">
        <span v-if="scope.row.refStatus === 1">已退费</span>
        <span v-if="scope.row.refStatus === 0">未退费</span>
      </template>
      <template #operation="scope">
        <el-button link type="primary" @click="lookFile(scope.row)">查看附件</el-button>
        <my-button link type="primary" title="退费办理" @click="handleRefund(scope.row)" />
        <my-button type="text" @click="handleDetail(scope.row)">详情</my-button>
        <el-button link type="primary" @click="handleUpdate(scope.row)">修改</el-button>
      </template>
    </my-table>
    <template #footer>
      <pagination v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
    </template>
  </InlineLayout>
  <dwDateil v-model="dialog.visible" :dialog-title="dialog.title" :current-row="currentRow" />
  <exportList v-model="dialog.isShow" :dialog-title="dialog.title" :current-row="currentRow" />
  <statusChange v-model="dialog.statusShow" :dialog-title="dialog.title" :current-row="currentRow" @handle-query="handleQuery" />
</template>

<script setup name="Ab07" lang="ts">
import { listAb01 } from '@/api/yuanshidian/ab01';
import { Ab01VO, Ab01Query, Ab01Form } from '@/api/yuanshidian/ab01/types';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
import dwDateil from '@/views/yuanshidian/ab01/components/addOrEdit';
import exportList from './components/exportList';
import statusChange from './components/statusChange';

const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const currentRow = ref({});

const fileList = ref([]);
const queryFormRef = ref<ElFormInstance>();
const paramsDataObj = ref({});
const dialog = reactive<DialogOption>({
  visible: false,
  auditIsShow: false,
  statusShow: false,
  title: '',
  isShow: false
});

const state = reactive({
  itemsDatas: [
    { label: '单位编码', prop: 'dw01', type: 'input' },
    { label: '单位名称', prop: 'dw02', type: 'input' },
    {
      label: '退费标识',
      prop: 'refStatus',
      type: 'select',
      options: [
        { value: 0, label: '未退费' },
        { value: 1, label: '已退费' }
      ]
    }
  ],
  tableData: [],
  columns: [
    { label: '序号', type: 'index', width: '55', prop: 'index' },
    // { type: 'selection' },
    { label: '统筹区编码', prop: 'aaa027', align: 'center', width: '150' },
    { label: '单位编码', prop: 'dw01', align: 'center', width: '150' },
    { label: '单位名称', prop: 'dw02', align: 'center', width: '150' },
    { label: '详细地址', prop: 'dw04', align: 'center', width: '180' },
    { label: '单位开户行', prop: 'dw08', align: 'center', width: '220' },
    { label: '单位法人', prop: 'dw10', align: 'center', width: '80' },
    { label: '单位联系人', prop: 'dw12', align: 'center', width: '100' },
    { label: '退费标识', prop: 'refStatus', align: 'center', type: 'custom', slot: 'refStatus', width: '80' },
    { label: '操作', type: 'operation', minWidth: '340px' }
  ],
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    dw01: '',
    dw02: '',
    refStatus: ''
  }
});
const { itemsDatas, tableData, columns, queryParams } = toRefs(state);
/** 查询原人员账户明细(缴费明细)列表 */
const getList = async () => {
  tableData.value = [];
  loading.value = true;
  const res = await listAb01(queryParams.value);
  tableData.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
};

/** 表单重置 */
const reset = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

//查看附件
const lookFile = (row) => {
  if (!row.fileurl) {
    proxy?.$modal.msgError('没有可查看的附件');
    return;
  }
  window.open(row.fileurl, '_blank');
};
/** 退费办理操作 */
const handleRefund = (row) => {
  currentRow.value = row;
  dialog.title = '退费办理';
  dialog.isShow = true;
};

/** 修改按钮操作 */
const handleUpdate = async (row) => {
  currentRow.value = row;
  dialog.title = '修改退费标识';
  dialog.statusShow = true;
};
/** 查看详情 */
const handleDetail = (row) => {
  currentRow.value.id = row.id;
  currentRow.value.type = 'detail';
  dialog.title = '查看原单位信息';
  dialog.visible = true;
};

onMounted(() => {
  getList();
});
</script>
